package com.lz.library.extension

import android.annotation.SuppressLint
import android.content.res.Resources
import android.os.Build
import androidx.annotation.ChecksSdkIntAtLeast

/**
 *  author: you : 2020/05/5
 */

/**
 * 8.0版本
 */
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.O)
fun hasO(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O

/**
 * 分区储存 9
 */
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.P)
fun hasP(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P

/**
 * 分区储存 10
 */
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.Q)
fun hasQ(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q

/**
 * android 11
 */
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.R)
fun hasR(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R

/**
 * android 11
 */
@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.R)
fun hasS(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S

/**
 * 推荐使用System的, 一些屏幕适配框架会改变Resource的density
 */
@SuppressLint("InternalInsetResource")
fun getStatusHeight(): Int = Resources.getSystem().run {
    val resId = getIdentifier("status_bar_height", "dimen", "android")
    if (resId > 0) getDimensionPixelOffset(resId) else 0
}